﻿<UserControl x:Class="ReportingManagement.Components.Queries.ReportParameterRetriever"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:ReportingManagement.Components.Validation"
             mc:Ignorable="d" x:Name="parameterValueRetriever"
             d:DesignHeight="67" d:DesignWidth="491">
    <UserControl.Resources>
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="Validation.ErrorTemplate">
                <Setter.Value>
                    <ControlTemplate>
                        <Border BorderBrush="Red" BorderThickness="3">
                            <AdornedElementPlaceholder />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <Border BorderThickness="0,0,0,5" Margin="0,0,0,5">
        <Border.BorderBrush>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                <GradientStop Offset="0" Color="Gray" />
                <GradientStop Offset="1" Color="LightGray" />
            </LinearGradientBrush>
        </Border.BorderBrush>
        <Grid Margin="5">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="3*" />
                <ColumnDefinition Width="2*" MinWidth="150" MaxWidth="250"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Label x:Name="lblParameterName" FontWeight="Bold" Padding="2,0" 
                   Content="{Binding ElementName=parameterValueRetriever, Path=ParameterName}" />
            <Label Grid.Row="1" Padding="2,0">
                <TextBlock x:Name="txtDescription" TextWrapping="Wrap" 
                           Text="{Binding ElementName=parameterValueRetriever, Path=ParameterDescription}"/>
            </Label>

            <local:ProxyElement 
                In="{Binding Path=ValidatingRegularExpression, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                Out="{Binding ElementName=regexValidator, Path=Expression}" />

            <AdornerDecorator  Grid.Column="1" Grid.RowSpan="2">                
                <TextBox x:Name="txtParameterValue" Background="#FFF6F6FA"
                     VerticalAlignment="Center" FontSize="24" TextChanged="txtParameterValue_TextChanged">                      
                    <TextBox.Text>
                        <Binding Path="ParameterValue" UpdateSourceTrigger="PropertyChanged">
                            <Binding.RelativeSource>
                                <RelativeSource Mode="FindAncestor" AncestorType="{x:Type UserControl}" />
                            </Binding.RelativeSource>
                            <Binding.ValidationRules>
                                <local:RegexValidationRule Expression="\d{5}" x:Name="regexValidator" />
                            </Binding.ValidationRules>
                        </Binding>
                    </TextBox.Text>
                </TextBox>
            </AdornerDecorator>            
        </Grid>
    </Border>
</UserControl>
